<link href="/Public/Home/public/all_common.css" rel="stylesheet" type="text/css">
<?php $this->Hinc('header')?>
<div id="dialog-modal" title="收货地址" style="display: none;"></div>
<div class="container clearfix">
    <div class="navbar step-two">
        <span>1 我的购物车</span>
        <span class="on">2 填写核对订单信息</span>
        <span>3 成功提交订单</span>
    </div>
    <div class="checkout-box">

            <div class="checkout-box-bd">
                <div class="xlj-box">
                    <div class="box-hd ">
                        <h2 class="title">收货地址</h2>
                    </div>
                    <div class="box-bd">
                        <div class="clearfix xlj-address-list" id="checkoutAddrList">
                            <!--地址信息-->
                            <?php foreach($dz as $v){?>
                            <dl class="item" data-addressid="112904">
                                <dt>
                                    <strong class="consignee">
                                        <p><input type="radio" class="dz" value="<?php echo $v['id']?>" name="dz[]"></p>
                                        <?php echo $v['name']?>
                                    </strong>
                                </dt>
                                <dd>

                                    <p class="telphone"> <?php echo $v['phone']?></p>
                                    <p class="address"> <?php echo $v['dizhi'].$v['dizhi_msg'];?></p>
                                    <p class="zipcode"> <?php echo $v['yzcode']?></p>
                                    <p>
                                        <a title="编辑" onclick="dz_edit('<?php echo $v[id]?>')" href="javascript:void(0)">
                                            <span class="address-edit" data-addressid="112904" data-type="checkout"></span>
                                        </a>
                                        &nbsp;&nbsp;
                                        <a title="删除" onclick="dz_del('<?php echo $v[id]?>')" href="javascirpt:void(0)">
                                            <span class="address-del"  data-addressid="112904" data-type="checkout"></span>
                                        </a>
                                    </p>
                                </dd>
                            </dl>
                            <?php }?>
                            <!--添加地址-->
                            <div class="item use-new-addr" id="AddNewAddress" data-type="checkout">
                                <span class="icon-add"></span>
                                添加新地址
                            </div>
                            <!--引入弹框插件-->
                            <script src="/Public/Admin/lib/layer/2.4/layer.js"></script>

                        </div>
                    </div>
                </div>
                <div id="checkoutPayment">
                    <div class="xlj-box">
                        <div class="box-hd ">
                            <h2 class="title">支付方式</h2>
                        </div>
                        <div class="box-bd-chekout">
                          <p> <input type="radio" class="pay" name="pay" value="支付宝支付"> 支付宝支付</p>
                          <p><input type="radio" class="pay" name="pay" value="余额支付"> 余额支付</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="checkout-box-ft clearfix">

                <div id="checkoutGoodsList" class="checkout-goods-box">
                    <div class="xlj-box">
                        <div class="box-hd">
                            <h2 class="title">商品信息</h2>
                        </div>
                        <div class="box-bd-chekout">
                            <table class="checkout-goods-list" cellpadding="0" cellspacing="0">
                                <thead>
                                <tr>
                                    <th class="col-1">商品名称</th>
                                    <th class="col-2">价格</th>
                                    <th class="col-2">购买数量</th>
                                    <th class="col-2">小计</th>
                                </tr>
                                </thead>
                                <tbody>
                                <!--显示购买商品数据-->
                                <?php $zje=0;foreach($arr as $v){?>
                                 <tr>
                                    <td class="col-1">
                                        <a style="color: #000000" href="<?php $this->U('Index','goods&id='.$v['g_id'])?>" target="_blank">
                                            <?php echo $v['name']?>
                                            &nbsp;&nbsp;|&nbsp;&nbsp;
                                            <?php echo $v['gname']?>
                                        </a>
                                    </td>
                                    <td class="col-2">￥<?php echo $v['money']+$v['gmoney']?>元</td>
                                    <td class="col-2"><?php echo $v['num']?></td>
                                    <td class="col-2">￥<?php echo $v['num']*($v['money']+$v['gmoney']);?>元</td>
                                </tr>
                                <?php
                                    $num=$v['num']*($v['money']+$v['gmoney']);
                                    $zje+=$num;
                                }?>
                                </tbody>
                            </table>
                            <div class="checkout-count clearfix">
                                <div class="checkout-price" id="checkout-price">
                                    <ul>
                                        <li>
                                            <?php echo count($arr);?>件
                                        </li>
                                        <li>
                                            总计：<strong id="totalPrice">￥<?php echo $zje?>元</strong>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="go-next clearfix">
                <a class="btn btn-back " href="<?php $this->U('Order','index')?>"> 返回购物车 </a>
                &nbsp;&nbsp;
                <a class="btn btn-primary" href="javascript:void(0)" id="orderNow" data-val="0">立即下单</a>

            </div>
            <input type="hidden" id="flow" value="<?php echo $_GET['id']?>">
        <!--定义表单提交数据-->
        <form action="/index.php?C=Order&F=index3" method="post" id="index3">
            <input type="hidden" name="dz" id="fdz">
            <input type="hidden" name="pay" id="fpay">
            <input type="hidden" name="flow" id="fflow">
        </form>
    </div>
</div>
<script>
    //立即下单
    $('#orderNow').click(function () {
       //获取数据,跳转到购物流程3
       //  获取地址
        var dz=0;
        $('.dz').each(function (i,t) {
            if($(t).is(":checked")){
                dz=$(t).val();
            }
        });

        //获取支付方式
        var pay=0;
        $('.pay').each(function (i,t) {
            if($(t).is(":checked")){
                pay=$(t).val();
            }
        });
        if(!dz||!pay){
            alert('请选择地址和支付方式!');
            return false;
        }

        //商品数据
        var flow=$('#flow').val();

        //给表单input框设置value,在提交表单
        $('#fdz').val(dz);
        $('#fpay').val(pay);
        $('#fflow').val(flow);
        $('#index3').submit();
    });

    //地址修改
    function dz_edit(id) {
        if(!id){
            return false;
        }
        layer.open({
            type: 2,
            title: '地址管理',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '500px'],
            content: "<?php $this->U('Order','dz_edit')?>&id="+id //iframe的url
        });
    }
    //地址删除
    function dz_del(id){
        if(id){
            if(confirm('是否删除')){
                $.get('<?php $this->U(Order,dz_del)?>',{id},function (abc) {
                    alert(abc.msg);
                    if(abc.type==1){
                        history.go(0);
                    }
                },'json');
            }
        }
    }
    $('#AddNewAddress').click(function () {
        //弹框提供用户输入信息
        layer.open({
            type: 2,
            title: '地址管理',
            shadeClose: true,
            shade: 0.8,
            area: ['500px', '500px'],
            content: "<?php $this->U('Order','dz_add')?>" //iframe的url
        });
    })
</script>
<?php $this->Hinc('footer')?>